import { Widget, _decorator, Node, Label, Toggle, ScrollView, Prefab, instantiate, Sprite } from 'cc';
import { UIBase } from '../scriptBase/UIBase';
import { UI } from '../enum/UI';
import { CfgLoginReward } from '../config/CfgLoginReward';
import { ArrayUtil } from '../util/ArrayUtil';
import { StorageUtil } from '../util/StorageUtil';
import { ShopItem } from '../uiItem/ShopItem';
import { GameUtil } from '../util/GameUtil';
const { ccclass, property, requireComponent } = _decorator;

//素材界面
@ccclass('UI/UIShopDetial')
@requireComponent(Widget)
export class UIShopDetial extends UIBase {

    @property(Label)
    public nameLab: Label = null;

    @property(Label)
    public desLab: Label = null;

    @property(Sprite)
    public iconSp: Sprite = null;

    private itemData:any;

    public onOpen(data?: any): void {
        this.itemData = data;
        this.refresh();
    }

    public onClose(data?: any): void {

    }

    protected onBtnCloseClick(): void {
        this.close()
    }

    public refresh(){
        this.nameLab.string = this.itemData.name;

        this.desLab.string = this.itemData.des;

        GameUtil.loadImage("itemImg/unLock/" + this.itemData.lockImage, this.iconSp);
    }

    protected onBtnGetAllClick(): void {
        this.close()
        this.open(UI.GetReward, CfgLoginReward)
        StorageUtil.setItem('loginRewardGetTime', Date.now())
    }

    protected onBtnGetOneClick(): void {
        this.close()
        this.open(UI.GetReward, [ArrayUtil.pickItem(CfgLoginReward)])
        StorageUtil.setItem('loginRewardGetTime', Date.now())
    }

}


